/*
作业要求：将 JS 对象数据保存 ./mydir/data.txt 文件中
    let data = { 
        "id": 4860, 
        "uuid": "5e398eef-f5cf-4ff6-a000-c24913de86dd", 
        "hitokoto": "万有引力可无法对坠入爱河的人负责。", 
        "type": "a", 
        "from": "金木研", 
        "from_who": null, 
        "creator": "夕之树", 
        "creator_uid": 4248, 
        "reviewer": 4756, 
        "commit_from": "web", 
        "created_at": "1573331301", 
        "length": 22 
    };
*/

// 1. 导入文件系统模块
const fs = require("fs");
// 2. 声明要求写入文件的内容变量
let data = `let data = { 
    "id": 4860, 
    "uuid": "5e398eef-f5cf-4ff6-a000-c24913de86dd", 
    "hitokoto": "万有引力可无法对坠入爱河的人负责。", 
    "type": "a", 
    "from": "金木研", 
    "from_who": null, 
    "creator": "夕之树", 
    "creator_uid": 4248, 
    "reviewer": 4756, 
    "commit_from": "web", 
    "created_at": "1573331301", 
    "length": 22 
};`;
// 3. 执行异步文件写入操作
fs.writeFile("./mydir/data.txt",data, err => {
    // 4. 判断成功与否
    if(err) throw err;
    // 5. 输出成功信息
    console.log("文件写入成功！");
});
    